package com.codyy.lib.base.application.repos.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.codyy.lib.base.application.AppContext
import com.codyy.lib.base.application.databinding.ItemArticleBinding
import com.codyy.lib.base.application.repos.model.DataXX

class ArticleAdapter :
    PagedListAdapter<DataXX, ArticleAdapter.ViewHolder>(object :
        DiffUtil.ItemCallback<DataXX>() {
        override fun areItemsTheSame(oldItem: DataXX, newItem: DataXX): Boolean =
            oldItem.id==newItem.id

        override fun areContentsTheSame(oldItem: DataXX, newItem: DataXX): Boolean =
            oldItem==newItem

    }) {
    class ViewHolder(itemView: View, private val binding: ItemArticleBinding) :
        RecyclerView.ViewHolder(itemView) {

        fun bindData(data: DataXX) {
            binding.data = data
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = ItemArticleBinding.inflate( LayoutInflater.from(AppContext), parent, false)
        return ViewHolder(binding.root, binding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
       getItem(position)?.let {
           holder.bindData(it)
           holder.itemView.setOnClickListener {

           }
       }
    }
}